<template>
  <div class="app-container">
    <!-- 搜索表单 -->
    <el-form :model="searchForm" ref="searchFormRef" size="small" :inline="true">
      <el-form-item label="标题" prop="name">
        <el-input v-model="searchForm.name" placeholder="请输入标题"></el-input>
      </el-form-item>

      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="searchForm.auditStatus" placeholder="请选择资讯类别" clearable>
          <el-option v-for="(item, index) in auditStatus" :key="index" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="资讯类别" prop="articleClass">
        <el-select v-model="searchForm.articleClass" placeholder="请选择资讯类别" clearable>
          <el-option v-for="(item, index) in articleClass" :key="index" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
          <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 内容表格 -->
    <el-table :data="reviewList">
      <el-table-column label="id" align="center" prop="informationId" />

      <el-table-column label="标题" align="center" prop="title" />

      <el-table-column label="来源" align="center" prop="source" width="100" />

      <el-table-column label="审核状态" align="center" prop="examineStatus">
        <template slot-scope="scope">
          {{
              scope.row.examineStatus != 0
                ? scope.row.examineStatus == 1
                  ? '审核通过'
                  : '审核失败'
                : '待审核'
          }}
        </template>
      </el-table-column>

      <el-table-column label="启用状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ scope.row.status == 0 ? '禁用' : '启用' }}
        </template>
      </el-table-column>

      <el-table-column label="资讯类别" align="center" prop="articleClass">
        <template slot-scope="scope">
          {{ handleInfoClassify(scope.row.articleClass) }}
        </template>
      </el-table-column>

      <el-table-column label="资讯栏目" align="center" prop="columnId">
        <template slot-scope="scope">
          {{ handelInfoColumnClassidy(scope.row.columnTitle), }}
        </template>
      </el-table-column>

      <el-table-column label="编辑者" align="center" prop="createBy" />

      <el-table-column label="创建时间" align="center" prop="createTime" width="200" />

      <el-table-column label="更新时间" align="center" prop="updateTime" width="200" />

      <el-table-column label="操作" align="center" width="250">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="selectContent(scope.row)">查看</el-button>

          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>

          <el-button size="mini" type="text" @click="aduitSuccess(scope.row)" v-if="scope.row.examineStatus == 0">通过
          </el-button>

          <el-button size="mini" type="text" @click="aduitFail(scope.row)" v-if="scope.row.examineStatus == 0">拒绝
          </el-button>

          <el-button size="mini" type="text" @click="toggleStatus(scope.row)">{{
              scope.row.status == 1 ? '禁用' : '启用'
          }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 页码 -->
    <el-pagination @current-change="handleCurrentChange" :current-page="queryParams.pageNum"
      :page-size="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="queryParams.total">
    </el-pagination>

    <!-- 查看当前审核模块的详细内容对话框 -->
    <el-dialog title="查看审核管理" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="thisRowReviewListRef" :model="thisRowReviewList" label-width="100px" :disabled="formDisabled">
        <el-form-item label="标题" prop="title">
          <el-input v-model="thisRowReviewList.title" placeholder="请输入标题" />
        </el-form-item>

        <el-form-item label="来源" prop="source">
          <el-input v-model="thisRowReviewList.source" placeholder="请输入来源" />
        </el-form-item>

        <el-form-item label="关键词" prop="keywords">
          <el-input v-model="thisRowReviewList.keywords" placeholder="请输入关键词" />
        </el-form-item>

        <el-form-item label="简介" prop="synopsis">
          <el-input v-model="thisRowReviewList.synopsis" placeholder="请输入简介" />
        </el-form-item>

        <el-form-item label="审核状态" prop="examineStatus">
          <el-select v-model="thisRowReviewList.examineStatus" placeholder="启用">
            <el-option v-for="item in auditStatus" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="启用状态" prop="status">
          <el-select v-model="thisRowReviewList.status" placeholder="启用">
            <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="资讯类别" prop="articleClass">
          <el-select v-model="thisRowReviewList.articleClass" placeholder="启用">
            <el-option v-for="item in articleClass" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="资讯栏目" prop="columnId">
          <el-select v-model="thisRowReviewList.columnId" placeholder="请选择">
            <el-option v-for="item in columnName" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {
  getReviewList,
  deleteInfo,
  toggleStatus,
  auditStatus
} from '@/api/fetv/review.js'
export default {
  data() {
    return {
      searchForm: {
        name: undefined,
        auditStatus: undefined,
        infoClass: undefined,
        status: undefined
      },

      auditStatus: [
        {
          label: '待审核',
          value: 0
        },
        {
          label: '审核通过',
          value: 1
        },
        {
          label: '审核失败',
          value: 2
        }
      ],

      articleClass: [
        {
          label: '新闻资讯',
          value: 0
        },
        {
          label: '视频',
          value: 1
        },
        {
          label: '外链',
          value: 2
        }
      ],

      status: [
        {
          label: '禁用',
          value: 0
        },
        {
          label: '启用',
          value: 1
        }
      ],

      columnName: [
        {
          label: '首页',
          value: 1
        },
        {
          label: '头条新闻',
          value: 2
        },
        {
          label: '要闻聚集',
          value: 3
        }
      ],

      // 内容表单的数据
      reviewList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        total: 10
      },

      // 审核管理详细内容对话框的展示
      open: false,

      // 当前行的数据
      thisRowReviewList: {},

      // 设置是否对话框的表单是否可以编辑
      formDisabled: true
    }
  },
  methods: {
    /** 查询栏目列表 */
    getReviewList() {
      getReviewList(this.queryParams).then((response) => {
        this.reviewList = response.rows
        this.queryParams.total = response.total
        console.log('请求数据')
      })
    },

    // 搜索功能
    handleQuery() { },

    // 重置功能
    resetQuery() { },

    // 查看
    selectContent(item) {
      this.open = true
      this.thisRowReviewList = item
    },

    // 删除
    handleDelete(item) {
      this.$confirm(
        `是否确认删除资讯管理编号为${item.informationId}的数据`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {
          deleteInfo(item.informationId)
          this.getReviewList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },

    // 切换状态
    toggleStatus(item) {
      toggleStatus({
        informationId: item.informationId,
        status: item.status == 0 ? 1 : 0
      }).then((response) => {
        this.$message.success('修改成功')
        this.getReviewList()
      })
    },

    // 将资讯进行分类
    handleInfoClassify(typeId) {
      switch (typeId) {
        case 1:
          return '新闻资讯'
        case 2:
          return '视频'
        case 3:
          return '外联'
        default:
          break
      }
    },

    // 将资讯栏目进行分类
    handelInfoColumnClassidy(id) {
      switch (id) {
        case 1:
          return '首页'
        case 2:
          return '头条新闻'
        case 3:
          return '要闻聚集'
        case 4:
          return '校园'
        case 5:
          return 'FETV'
        case 6:
          return '招考'
        case 7:
          return '空中课堂'
        case 8:
          return '家长'
        case 9:
          return '师说'
        case 10:
          return '职场'
        case 11:
          return '微视频'

        default:
          return '更多'
      }
    },

    // 改变页码
    handleCurrentChange(val) {
      this.queryParams.pageNum = val
      this.getReviewList()
    },

    // 审核通过
    aduitSuccess(item) {
      this.$confirm(`是否通过id为${item.informationId}的数据`, '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          auditStatus({
            informationId: item.informationId,
            examineStatus: 1
          }).then((response) => {
            this.$message({
              type: 'success',
              message: '已通过!'
            })
            this.getReviewList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },

    // 审核失败
    aduitFail(item) {
      this.$confirm(`是否拒绝id为${item.informationId}的数据`, '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          auditStatus({
            informationId: item.informationId,
            examineStatus: 2
          }).then((response) => {
            this.$message({
              type: 'success',
              message: '已拒绝!'
            })
            this.getReviewList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },

  },
  created() {
    this.getReviewList()
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-pagination {
  float: right;
  margin-top: 20px;
}
</style>
